<template>
	<!-- 隐患督办 -->
	<view class="">
		<u-navbar title="隐患督办" :placeholder="true" leftIconColor="#fff" @rightClick="openPopup" titleStyle="color: #fff" bgColor="#2172FC" :autoBack="true">
			<template #right>
				<u-icon name="hourglass" color="#fff" size="25"></u-icon>
			</template>
		</u-navbar>
	</view>
	<view class="p-10">
		<u-sticky class="p-10" style="background-color: #fff">
			<u-subsection :list="tabList" activeColor="#2172FC" :current="currentKey" mode="subsection" @change="handleTabClick"></u-subsection>
		</u-sticky>
		<template v-if="list.length > 0">
			<view class="card" v-for="(item, index) in list" @click="goDetail(item)">
				<view class="flex m-between">
					<view class="name fw">
						{{ item.supervisionTypeName }}
					</view>
				</view>
				<view class="flex m-between m-t-8">
					<view class="post">地点: {{ item.riskLocationName }}</view>
					<view class="pro">日期: {{ item.checkDate }}</view>
				</view>
				<view class="flex m-between m-t-8">
					<view class="post">隐患等级: {{ item.hiddenLevelName }}</view>
					<view class="pro">责任人: {{ item.dutyUserName }}</view>
				</view>
				<view class="flex m-between m-t-8">
					检查人:
					<up-text :lines="1" :text="item.inspectUserNames"></up-text>
				</view>
			</view>
		</template>
		<u-empty v-else mode="data"></u-empty>
	</view>
	<!-- 筛选popup -->
	<my-popup :show="showPopup" :queryParams="queryParams" :formItem="formData" @close="closePopup" @reset="reset" @submit="submit"></my-popup>
	<u-back-top :scroll-top="scrollTop" top="600"></u-back-top>
</template>
<script setup>
import { onShow } from '@dcloudio/uni-app';
import { reactive, ref, computed } from 'vue';
import { pageSupervision } from '@/api/hidden-danger.js';
import Dict from '@/store/dict.js';
import useList from '@/hooks/useList.js';

const dict = Dict();
let currentKey = ref(0),
	queryParams = reactive({
		pageNum: 1,
		pageSize: 10,
		state: 0,
		startTime: '',
		endTime: ''
	}),
	tabList = [
		{
			name: '未处理'
		},
		{
			name: '已处理'
		}
	],
	formData = computed(() => {
		return [
			{
				itemType: 'select',
				label: '隐患等级',
				type: 'hidden_danger_level',
				prop: 'hiddenLevel'
			},
			{
				label: '隐患专业',
				type: 'specialty_key',
				itemType: 'select',
				prop: 'specialty'
			},
			{
				label: '地点',
				itemType: 'select',
				list: checkList.value,
				prop: 'riskLocationId'
			},
			{
				itemType: 'select',
				type: 'GETuseList',
				label: '责任人',
				prop: 'dutyUserId'
			}
		];
	});
// 重置表单
const reset = () => {
	queryParams.hiddenLevel = '';
	queryParams.specialty = '';
	queryParams.riskLocationId = '';
	queryParams.dutyUserId = '';
	getListData();
};
// 查询
const submit = () => {
	getListData();
	showPopup.value = false;
};
const handleTabClick = (index) => {
	currentKey.value = index;
	queryParams.state = index;
	queryParams.pageNum = 1;
	getListData();
};
// 跳转详情
const goDetail = (item) => {
	uni.navigateTo({
		url: '/pages/professional/hiddenTrouble/supervise/hiddenDetail?data=' + JSON.stringify(item)
	});
};
// 字典数据
const getDicts = () => {
	dict.GETspecialtyKey();
};
const { getListData, getCheckPonit, list, checkList, showPopup, openPopup, closePopup } = useList({
	queryParams,
	api: {
		page: pageSupervision
	}
});
// 初始化数据
const init = () => {
	getListData();
	getDicts();
	getCheckPonit();
};
onShow(() => {
	init();
});
</script>
<style lang="scss" scoped></style>
